/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.dialog;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import de.mnit.basis.daten.MN;
import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.swt.anw.A_MN_Dialog;
import de.mnit.basis.swt.anw.A_MN_Gruppe;
import de.mnit.basis.swt.element.S_SWT_Komponente;
import de.mnit.basis.swt.element.steuer.SWT_Knopf;
import de.mnit.basis.swt.element.steuer.SWT_Label;
import de.mnit.basis.swt.element.steuer.rollbar.SWT_TextEingabe;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.bild.deko.SWT_Fenster;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.bild.deko.S_Fenster;
import de.mnit.basis.swt.grafik.icon.direkt.ICON;
import de.mnit.basis.swt.layout.LayoutAbsolut;

/**
 * @author Michael Nitsche
 * 17.03.2007	Erstellt
 */
public class Dialog_Text extends A_MN_Dialog<Dialog_Text, String> {

	public static void main(String[] par)  { start(Dialog_Text.class, "Test:"); }


	private final SWT_Label       k_label   = new SWT_Label();
	private final SWT_TextEingabe k_eingabe = new SWT_TextEingabe();
	private final SWT_Knopf       k_ok      = new SWT_Knopf();
	private final String label, init;


	public Dialog_Text(String label) {
		this(label, null);
	}

	public Dialog_Text(String label, String init) {
		Fehler.objekt.wenn_Null(label);
		this.label=label;
		this.init=init;
	}


	protected S_SWT_Komponente<?, ? extends Composite> layout() {
		return LayoutAbsolut.neu()
			.sKomponente(t.k_label).sLORU(10, 10, 10, null).fertig()
			.sKomponente(t.k_eingabe).sLORU(10, 30, 10, null).fertig()
			.sKomponente(t.k_ok).sRU(10, 10).sBreite(75).fertig()
		;
	}

	protected void initStyle() {
		t.k_ok.sBild(ICON._16.AKTION_OK);
		t.k_label.sText(this.label);
		t.k_eingabe.sText(MN.beiNull(this.init, ""));
	}

	protected void initEvents() {
		Listener l=new Listener(){
			public void handleEvent(Event event) {
				t.schliessen();
			}
		};
		t.k_ok.eAuswahl(l);
		t.k_eingabe.eTasteEnter(l);
	}

	protected S_Fenster<?> fenster(A_MN_Gruppe<?> instanz) {
		return SWT_Fenster.neu(instanz, true, 250, 110, "Text-Eingabe", ICON._16.OBJ_ERDE);
	}

	protected String gErgebnis2() {
		return t.k_eingabe.gText();
	}

}
